﻿namespace WingBeats.CSS.Attributes
open System

type CssPropertyAttribute(name : string) =
    inherit Attribute()
    member this.Name = name

type CssValueTypesAttribute(types : string array) =
    inherit Attribute()
    member this.CssValueTypes  = types

type CssValueEditorAttribute(name : string, validDataTypes : System.Type array) =
    inherit Attribute()
    member this.Name = name
    member this.ValidDataTypes = validDataTypes

module ActivePatterns =

    let isDecorated<'a> (t : System.Type) =
        let attribute = 
            t.GetCustomAttributes(false)
            |> Seq.tryFind (function | :? 'a -> true
                                     | _     -> false)
        match attribute with
        | Some (a) -> Some (t, (a :?> 'a) )
        | None     -> None

    let (|CssPropertyBeat|_|) = isDecorated<CssPropertyAttribute   >
    let (|CssValueType   |_|) = isDecorated<CssValueTypesAttribute >
    let (|CssValueEditor |_|) = isDecorated<CssValueEditorAttribute>